package Gabor.hibernate;

import org.hibernate.Query;
import org.hibernate.Session;

import java.util.List;

public class TestExceptions {

    Session session = null;

    public TestExceptions() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public int getUserCount() {
        int userCount = -1;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query query = session.createQuery ("from UserEntity");
            userCount = query.list().size();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return userCount;
    }
    public List getUserNames() {
        List userNames = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query query = session.createQuery ("from UserEntity");
            userNames = query.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return userNames;
    }
}